﻿<%@ WebService Language="C#" Class="tb_ws" %>
using System;
using System.Web;
using System.IO;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Runtime.Serialization.Formatters.Binary;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class tb_ws  : System.Web.Services.WebService {

    [WebMethod]
    public int InsertDianpu(TB.Entity.dianpu obj)
    {
        TB.BLL.Dianpu dpBLL = new TB.BLL.Dianpu();
        return dpBLL.Add(obj);   
    }

    [WebMethod]
    public int InsertDesigner(TB.Entity.Desinger obj)
    {
        TB.BLL.Desinger designerBll = new TB.BLL.Desinger();
        return designerBll.Add(obj);
    }

    [WebMethod]
    public int InsertTemplate(TB.Entity.Template obj)
    {
        TB.BLL.Template templateBll = new TB.BLL.Template();
        return templateBll.Add(obj);
    }

    [WebMethod]
    public int GetDianpuSum()
    {
        TB.BLL.Dianpu dpBLL = new TB.BLL.Dianpu();
        return dpBLL.GetDianpuSum();    
    }

    [WebMethod]
    public int UpdateTemplateID(int shopid,string templateId)
    {
        TB.BLL.Dianpu dpBll = new TB.BLL.Dianpu();
        return dpBll.UpdateTemplateID(shopid, templateId);
    }
    [WebMethod]
    public byte[] GetDpURLRecord(int topNum,string colName)
    {
        TB.BLL.Dianpu dp = new TB.BLL.Dianpu();
        DataSetSurrogate dss = new DataSetSurrogate(dp.GetRecord(topNum, colName));
        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ser = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        ser.Serialize(ms, dss);
        byte[] buffer = ms.ToArray();
        byte[] Zipbuffer = Compress(buffer);
        return Zipbuffer;
    }

    public byte[] Compress(byte[] data)
    {
        MemoryStream ms = new MemoryStream();
        Stream zipStream = null;
        zipStream = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, true);
        zipStream.Write(data, 0, data.Length);
        zipStream.Close();
        ms.Position = 0;
        byte[] compressed_data = new byte[ms.Length];
        ms.Read(compressed_data, 0, int.Parse(ms.Length.ToString()));
        return compressed_data;
    }
    [WebMethod]
    public string GetReqIp()
    {
        string ip=HttpContext.Current.Request.UserHostAddress;
        return ip;
    }
   
    [WebMethod]
    public System.Data.DataSet GetGxDpURL(ref int noGxSum,string zdDate,int daysNum)
    {
        TB.BLL.Dianpu dp = new TB.BLL.Dianpu();
        return dp.GetGxDpUrl(out noGxSum,zdDate,daysNum);
    }
}